package com.aoxon.cargo.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.aoxon.cargo.R;
import com.aoxon.cargo.adapter.PubPicturePagerAdapter;
import com.aoxon.cargo.bean.Picture;
import com.aoxon.cargo.cache.SupCache;
import com.aoxon.cargo.state.DataState;

public class PubPicturePagerActivity extends BaseActivity {

	public static boolean ROOT = false;
	public static int SHOW_ITEM = 0;

	private List<Picture> pictures = new ArrayList<Picture>();
	private PubPicturePagerAdapter adapter;
	private ImageView ivBackButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pub_view_pager);
		ViewPager mViewPager = (ViewPager) findViewById(R.id.view_pager);
		
		ivBackButton = (ImageView) findViewById(R.id.ivPurDetailsBack);
		ivBackButton.setOnClickListener(onClickListener);
		
		adapter = new PubPicturePagerAdapter(this, pictures);

		if (SupCache.pictureList != null) {
			for (int i = 0; i < SupCache.pictureList.size(); i++) {
				Picture picture = SupCache.pictureList.get(i);
				if (picture.getPictureState() != DataState.DELETE
						&& picture.getPictureState() != DataState.HAVE_BUT_DELETE) {
					pictures.add(picture);
				}
			}
		}
		mViewPager.setAdapter(adapter);
		adapter.notifyDataSetChanged();

		mViewPager.setCurrentItem(SHOW_ITEM);
	}
	
	OnClickListener onClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.ivPurDetailsBack:
//				Intent intent = new Intent(getBaseContext(),SupFillInfo4Activity.class);
//				startActivity(intent);
				PubPicturePagerActivity.this.finish();
				break;
			default:
				break;
			}
		}
	};

	@Override
	public void finish() {
		super.finish();
		SupCache.fromCamera = false;
	}
}
